<!--
*@Author: QWP
*@Description: 消息推送
*@Date: 2024-09-12 17:04:38
-->
<template>
  <u-dialog v-bind="$attrs"
    destroyOnClose
    :confirmLoading="loading"
    @submit="submit"
    @close="dialogClose">
    <u-form :elements="formEls"
      :model="form"
      :gutter="0"
      :disabled="isCheck"
      ref="formRef"
      style="padding: 16px 0;">
    </u-form>
  </u-dialog>
</template>

<script lang='ts' setup>
import { ref, reactive, computed, onMounted, h, watch, useAttrs } from 'vue' 
import { useRoute, useRouter } from 'vue-router'
import { FormInstance, FormItemProps } from 'ant-design-vue';
import { nullC, alertC, messageC } from '@/util/common'
import dayjs from 'dayjs';
import * as userApi from '@/service/system/user'
import * as chatApi from '@/service/emergency/chat/index.ts'
import * as incomeApi from '@/service/officialDoc/incomeDoc'
import { cloneDeep } from 'lodash'

const props = defineProps<{
  current?: object,
}>()

const attrs = useAttrs()
const emits = defineEmits(['success'])

const loading = ref<boolean>(false)
const formRef = ref<FormInstance>()
const form = ref({})
const formItemProps = {
  labelWidth: '120px',
  colon: false, 
}

const formEls: Array<any> = [
  { label: '接收人员', key: 'userlist', element: 'selRoleUserTree', formItemProps: { ...formItemProps, required: true }, col: { span: 24} , 
    componentProps: { 
      fieldNames: { label: 'name', value: 'keyid' },
      disabled: true,
      multiple: true,
      class: 'f-normal-disable',
      parent: { key: 'roleName', valueKey: 'fkparentid', parentTLable: '角色名称' },
    }
  },
  // { label: '备注', key: 'messageInfo', element: 'textarea', formItemProps, col: { span: 24} , },
]

// 保存提交
const submit = async(type?: string) => {
  try {
    await formRef.value.form.validate()
  } catch (error) {
    alertC("请先选择接收人员!");
    return
  }

  await alertC("确认推送？", 'confirm')
  loading.value = true;
  try {
    const res = await incomeApi.incaccptnotice(props.current['keyid'], form.value.userlist)
    if(res.code == 0) {
      messageC(res.msg, "success")
      emits('success')
      dialogClose()
    }
    else {
      messageC(res.msg, "error")
    }
  } catch (error) { }
  loading.value = false;
}

const dialogClose = () => {
  form.value = {}
  formRef.value.form.resetFields();
}
</script>

<style lang='scss' >
</style>